﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using WFNetLib.StringFunc;
using WFNetLib;

namespace 生命体征测试仪
{
    public partial class formNurse : formBase
    {
        public formNurse()
        {
            InitializeComponent();
        }
        NurseList nurseList;
        private void formNurse_Load(object sender, EventArgs e)
        {
            refresh();
        }
        void refresh()
        {
            del1.Visible = false;
            del2.Visible = false;
            del3.Visible = false;
            del4.Visible = false;
            nurseList = WebWork.QueryNurse(StringsFunction.byteToHexStr(SoftVerify_byMachineCode.GetMachineCode(), ""));
            if (nurseList == null)
            {
                MessageBox.Show("与服务器建立连接失败，请稍后重试");
                this.Close();
                return;
            }
            if (nurseList.list == null)
                return;
            for (int i = 0; i < nurseList.list.Count; i++)
            {
                switch (i)
                {
                    case 0:
                        del1.Visible = true;
                        del1.Text = "删除 " + nurseList.list[0].Name + " 护士";
                        break;
                    case 1:
                        del2.Visible = true;
                        del2.Text = "删除 " + nurseList.list[1].Name + " 护士";
                        break;
                    case 2:
                        del3.Visible = true;
                        del3.Text = "删除 " + nurseList.list[2].Name + " 护士";
                        break;
                    case 3:
                        del4.Visible = true;
                        del4.Text = "删除 " + nurseList.list[3].Name + " 护士";
                        break;
                }
            }
        }
        private void del1_Click(object sender, EventArgs e)
        {
            RegResult ret = WebWork.DeleteNurse(nurseList.list[0].ID);
            if (ret != null && ret.message == "ok")
                MessageBox.Show("删除成功");
            else
                MessageBox.Show("删除失败");
            refresh();
        }
        private void del2_Click(object sender, EventArgs e)
        {
            RegResult ret = WebWork.DeleteNurse(nurseList.list[1].ID);
            if (ret != null && ret.message == "ok")
                MessageBox.Show("删除成功");
            else
                MessageBox.Show("删除失败");
            refresh();
        }
        private void del3_Click(object sender, EventArgs e)
        {
            RegResult ret = WebWork.DeleteNurse(nurseList.list[2].ID);
            if (ret != null && ret.message == "ok")
                MessageBox.Show("删除成功");
            else
                MessageBox.Show("删除失败");
            refresh();
        }
        private void del4_Click(object sender, EventArgs e)
        {
            RegResult ret = WebWork.DeleteNurse(nurseList.list[3].ID);
            if (ret != null && ret.message == "ok")
                MessageBox.Show("删除成功");
            else
                MessageBox.Show("删除失败");
            refresh();
        }
        private void skinButton2_Click(object sender, EventArgs e)
        {
            if (nurseList.list.Count > 3)
            {
                MessageBox.Show("当前护士数量已最大，请删除某个后再添加");
                return;
            }
            formGetID f = new formGetID();
            f.ShowDialog();
            if(f.bIDOk)
            {
                NurseData n = new NurseData();
                n.ID = formMain.curUser.ID;
                n.Name = formMain.curUser.Name;
                n.Nation = formMain.curUser.Nation;
                n.Sex = formMain.curUser.Sex;
                n.Born = formMain.curUser.Born;
                n.TEID = StringsFunction.byteToHexStr(SoftVerify_byMachineCode.GetMachineCode(), "");
                RegResult ret = WebWork.AddNurse(n);
                if (ret != null && ret.message == "ok")
                    MessageBox.Show("添加成功");
                else if (ret != null && ret.message == "repeat")
                    MessageBox.Show("当前护士已经存在");
                else
                    MessageBox.Show("添加失败");
                refresh();
            }
            try
            {
                string stmp = System.Windows.Forms.Application.StartupPath + "\\身份证照片";
                string file = stmp + "\\" + formMain.curUser.ID + ".bmp";
                FileOP.Delete(file, FileOPMethod.File);
                file = stmp + "\\" + formMain.curUser.ID + ".jpg";
                FileOP.Delete(file, FileOPMethod.File);
            }
            catch //(System.Exception ex)
            {

            }
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
    }
}
